<template>
	<scroll-view scroll-y class="bgf5 group c00" :style="{height: 'calc(100vh - ' + statusBar + 'px)'}">
		<view v-for="(item,index) in list" :key="index" class="px10 bgff r6 py12 my10 mx16 shadow">
			<view class="bold6 pb8">{{item.name}}~</view>
			<view class="flex flexC fs12 pb12 box">
				<text class="flex1">有效期至：购买后{{item.take_valid_day}}天有效</text>
				<view class="mr4">
					<view class="origin">{{item.discount_type}}</view>
					<view class="c57 mt2" v-if="item.discount_type == '时长抵扣'">折扣值:{{item.discount_val}}小时</view>
					<view class="c57 mt2" v-if="item.discount_type == '金额抵扣'">折扣值:￥{{item.discount_val}}元</view>
					<view class="c57 mt2" v-if="item.discount_type == '折扣抵扣'">折扣值:￥{{item.discount_val}}折</view>
					
				</view>
				<view class="cff0">
					<text class="fs12"></text>
					<text class="fs28 bold6"></text>
				</view>
			</view>
			<view class="flex flexC pt12">
				<view @click="openItem(item)" class="flex1 flexC flex ">
					<text class="c9d fs12">抵扣券使用的包厢：</text>
					<image class="w10" :class="item.check ? 'up' : ''" src="/static/img/icon/up.png" mode="aspectFill"></image>
				</view>
				<text class="bg41 r40 px10 py2" @click="send(item)">发放</text>
				<text class="bg41 r40 px10 ml10 py2" @click="close(item)">作废</text>
			</view>
			<view v-if="item.check" class="mt6 bgff">
				<view class="fs12 px10 mb5" v-for="(rule,index) in item.rooms" :key="subIndex">
					<text class="c2e">{{rule.room_name}}</text>
				</view>
				
				<!-- <view class="fs12 px10 mb5" @click="look(item)">
					<text class="c57">查看使用门店></text>
				</view> -->
			</view>
		</view>
		
		<!-- 团购券使用范围弹框 -->
		<uni-popup type="center" ref="popup">
			<view class="bgff r10 px30 pb20 flex flexC flexJC flexCol">
				<view class="fs16 bold6 py22">团购券使用范围</view>
				<view class="bor57 aliC" >
					<view class="flex flexC borb57">
						<view class="left py5">适用门店</view>
						<view class="right py5">适用包间</view>
					</view>
					<view class="flex flexC fs12" v-for="item in item.rooms">
						<view class="left">【{{item.room_name}}】</view>
						<!-- <view class="right">
							<view v-for="(sub,index) in item.room" :key="index" class="py4">{{sub.name}}</view>
						</view> -->
					</view>
				</view>
				<button class="bg57 r40 w-15 fs14 mt20" @click="$refs.popup.close()">好的，知道啦</button>
			</view>
		</uni-popup>
	</scroll-view>
</template>

<script>
	export default {
		name:"group-coupon",
		props: {
			statusBar: {
				type: Number,
				default: 20
			},
			selectShop: {
				type: [String, Number],
				default: ''
			}
		},
		data() {
			return {
				isChecked: false,
				page:1,
				list:[],
				currentShopRoom:[]
			};
		},
		methods: {
			
			send(item){
				
				uni.navigateTo({
					url:'../discount/send?id='+item.id
				})
				
			},
			
			close(item){
				
				
				let param = {
					tuan_id:item.id
				};
				let that = this;
				this.$api.closeDiscount(param).then(res => {
					console.info(JSON.stringify(res));
					if (res.code == 1) {
						uni.showModal({
							title:"操作提示",
							content:"作废成功",
							showCancel:false,
							complete() {
								that.$emit("refresh")
								
							}
						})
					} else {
						uni.showToast({
							icon:'none',
							title:res.msg
						})
					}
				})
			},
			
			
			openItem(item){
				
				// for(var i=0;i<this.list.length;i++){
				// 	this.list[i].check = false;
				// }
				if(item.check == true){
					item.check = false;
				}else{
					item.check = true;
				}
		
				console.info("==item check=="+item.check);
			},
			look(item){
				let param = {
					id:item.id,
				};
				let that = this;
				this.$api.lookRoom(param).then(res => {
					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.currentShopRoom = res.data;
						that.$refs.popup.open();
						
					} else {
						uni.showToast({
							icon:'none',
							title:res.msg
						})
					}
				})
				
			},
			getData(selectShop) {
				
				let param = {
					shop_id:selectShop.id,
					page:this.page
				};
				let that = this;
				this.$api.discountList(param).then(res => {
					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.list = res.data;
					} else {
				
					}
				})
				console.log(selectShop)
				
			}
		}
	}
</script>

<style lang="scss" scoped>
.group {
	.box {
		border-bottom: 4rpx dashed #eee;
		.origin {}
	}
	.w10 {
		width: 20rpx;height: 12rpx;
		transform: rotate(90deg);
		transition: .5s;
		&.up {
			transform: rotate(180deg);
		}
	}
	.borb57 {border-bottom: 2rpx solid #576DAB;}
	.left {width: 200rpx;height: 100%;}
	.right {width: 300rpx;border-left: 2rpx solid #576DAB;}
}
</style>